---@class Battle.AiCondition:Battle.AiDecorator
local AiCondition = Battle.CreateClass("AiCondition",Battle.AiDecorator)
Battle.AiCondition = AiCondition
local t = AiCondition

function t:SetCondition(condition1,condition2,compareType)
    self.condition1 = condition1
    self.condition2 = condition2
    self.compare = compareType
end
function t:GetCondition1Value()
    if type(self.condition1) == "function" then
        return self.condition1(self:GetTree().actor)
    else
        return self.condition1
    end
end
function t:GetCondition2Value()
    if type(self.condition2) == "function" then
        return self.condition2(self:GetTree().actor)
    else
        return self.condition2
    end
end
function t:IsTrigger()
    return Battle.BattleUtil.CheckCondition(self:GetCondition1Value(),self.compare,self:GetCondition2Value())
end
function t:tick(dt)
    if self.status ~= Battle.AiTreeStatus.RUNNING then
        self:onInitialize();
    end
    local flag = self:IsTrigger()
    if not flag then
        return Battle.AiTreeStatus.FAILURE
    end
    if self.status ~= Battle.AiTreeStatus.RUNNING then
        self:reset()
    end
    return self:doTick(dt)
end
function t:doTick(dt)
    self:GetTree():AddExecute(self)
    self.status = self:update(dt)
    return self.status
end
function t:update(dt)
    if self.child then
        return self.child:tick(dt)
    end
    return Battle.AiTreeStatus.FAILURE
end
